#pragma once
#include "IndexedGeometry.h"
#include "IndexedFace.h"

#include <vector>
/**
* This class allows the easy creation of a triangle list.
* // TO DO sort the triangles for better performance (vertex caching)
* @author Koen Samyn
*/
class TriangleList:public IndexedGeometry
{
public:
	/**
	* Create a triangle list with the provided number of triangles.
	* @param nrOfTriangles the number of triangles in the trianglelist.
	*/
	TriangleList(int nrOfTriangles);
	/**
	* Destroys the TriangleList object.
	*/
	virtual ~TriangleList(void);
	/**
	* Adds an IndexedFace to the list of triangles.
	* @param face the IndexedFace to add.
	*/
	int AddIndexedFace(IndexedFace face);
	/**
	* Adds a triangle to the list of triangles.
	* @param index1 the first index of the triangle.
	* @param index2 the second index of the triangle.
	* @param index3 the third index of the triangle.
	*/
	int AddIndexedFace(int index1,int index2,int index3);
	/**
	* Gets the indices of a specified triangle.
	* @param triangleIndex the index of the triangle.
	* @param index1 the first index of the triangle.
	* @param index2 the second index of the triangle.
	* @param index3 the third index of the triangle.
	*/
	void GetIndexedFace(int triangleIndex, int* index1, int* index2, int* index3 );
	/**
	* Sets the indices for a specific triangle.
	* @param triangleIndex the index of the triangle.
	* @param index1 the first index of the triangle.
	* @param index2 the second index of the triangle.
	* @param index3 the third index of the triangle.
	*/
	void SetIndexedFace(int triangleIndex, int index1, int index2, int index3);
	/**
	* Gets the current number of triangles in this triangle list.
	* @return the current number of triangles in this list.
	*/
	int GetCurrentNrOfTriangles(){
		return (m_CurrentIndex)/3;
	}
	/**
	* Gets the size in bytes for this TriangleList.
	* @return the size in bytes.
	*/
	unsigned int GetSizeInBytes(){
		return m_Indices.size() * sizeof( unsigned int);
	}
	/**
	* Returns a pointer to the internal indexbuffer.
	* @return a pointer to the indices.
	*/
	void* GetData(){return &m_Indices[0];}
	/**
	* Returns the type of primitive.
	* @return the primitive type.
	*/
	PRIMITIVE GetPrimitiveType(){ return TRIANGLES;}
	/**
	* Returns the number of primitives to draw.
	* @return the number of primitives.
	*/
	int GetNumberOfPrimitives(){
		return GetCurrentNrOfTriangles();
	}
	/**
	* Updates the indices (check for minimum and maximum indices).
	*/
	void UpdateIndices();
private:
	int m_CurrentIndex;
	int m_NrOfTriangles;
	bool m_Valid;
	std::vector<unsigned int> m_Indices;
	// -------------------------
	// Disabling default copy constructor and default assignment operator.
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
	// an error in your class, these declarations are deliberately made without implementation because they should never be used.
	// -------------------------
	TriangleList(const TriangleList& t);
	TriangleList& operator=(const TriangleList& t);
};